package com.ruoyi.ipms_patent.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.ipms_patent.entity.CaseHistory;
import com.ruoyi.ipms_patent.service.CaseHistoryService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/*案件历史controller*/
@RestController
@RefreshScope
@RequestMapping("/patent/history")
public class CaseHistoryController extends BaseController {

    @Resource
    private CaseHistoryService caseHistoryService;

    /*新增案件历史记录*/
    @PostMapping("/add")
    public AjaxResult addOne(@RequestBody CaseHistory history) {

        System.out.println("-------------"+history);

        CaseHistory result = caseHistoryService.addCaseHistory(history);
        return result != null ? AjaxResult.success("新增成功", result) : error("新增失败");
    }

    /*全部案件历史列表分页（根据案件id）*/
    @GetMapping("/find/{caseId}")
    public AjaxResult findListByCaseId(@PathVariable("caseId") Integer caseId) {
        return AjaxResult.success("案件历史列表",caseHistoryService.findCaseHistoryList(caseId));
    }


    /* 插入案件历史记录 */
    @GetMapping("/insert/{caseIds}/{caseHistoryStatusDescrip }")
    public AjaxResult insertCaseHistory(@PathVariable("caseIds") List<Integer> caseIds,@PathVariable("caseHistoryStatusDescrip ") String caseHistoryStatusDescrip ) {
        return toAjax(caseHistoryService.insertCaseHistory(caseIds,caseHistoryStatusDescrip ));
    }

    /*全部案件历史列表分页（根据案件编号）*/
    @GetMapping("/query/{caseNo}")
    public AjaxResult findListByCaseNo(@PathVariable("caseNo") String caseNo) {
        List<CaseHistory> caseHistoryList = caseHistoryService.findListByCaseNo(caseNo);
        return AjaxResult.success(caseHistoryList);
    }
}
